﻿@using KingRoad.EPM.Common.Helper
@{
    Layout = null;
    ViewBag.Title = "操作权限管理——公路工程建设项目造价全过程管理系统";
}
<script type="text/javascript">
    var contentHeight_Permission_Item_Index = 0;
    $(function () {
        //计算分栏高度
        contentHeight_Permission_Item_Index = $("#tabContent").innerHeight() - $(".panelBar",navTab.getCurrentPanel()).outerHeight();
        $("#mainContent_Permission_Item_Index").height(contentHeight_Permission_Item_Index);
    });
    //树
    var zNodes_Permission_Item_Index = [];
    var _selectedID_Permission_Item_Index = "";
    var zTree_Permission_Item_Index;
    var setting_Permission_Item_Index;
    //全局的href
    var href__Permission_Item_Index = "/Permission/PermissionItem";
    setting_Permission_Item_Index = {
        checkable: false,
        async: true,
        isSimpleData: true,
        editable: true,
        edit_removeBtn: false,
        edit_renameBtn: false,
        dragCopy: true,
        dragMove: true,
        asyncUrl: "/Permission/Module/GetModuleMenus",  //获取节点数据的URL地址
        //asyncDataFilter: ajaxDataFilter,
        nameCol: "FullName",
        open: true,
        treeNodeKey: "Id",
        treeNodeParentKey: "ParentId",
        callback: {
            //             beforeAsync: zTreeBeforeAsync,
            asyncSuccess: zTreeOnAsyncSuccess_Permission_Item_Index,
            //             asyncError: zTreeOnAsyncError,
            click: zTreeOnClick_Permission_Item_Index
        }
    };

    function zTreeOnAsyncSuccess_Permission_Item_Index(event, treeId, treeNode, msg) {
        //异步成功
    }

    //树的单击事件

    function zTreeOnClick_Permission_Item_Index(event, treeId, treeNode) {
        GridGet_Permission_Item_Index();
        //修改为单击模块右侧显示其操作权限列表 WS 2011.11.3
        $("#List_Permission_Item_Index").trigger("reloadGrid");
        var addUrl_Permission_Item_Index = href__Permission_Item_Index + "/Create/" + treeNode.Id;
        $("#add_Permission_Item_Index").attr("href", addUrl_Permission_Item_Index);
        _selectedID_Permission_Item_Index = "";
    }

    $(document).ready(function () {
        refreshTree("/Permission/Module/GetModuleMenus");
        //模块删除操作
        $("#del_Permission_Item_Index").click(function () {

            if (_selectedID_Permission_Item_Index != "") {
                alertMsg.confirm("您确定要删除吗？", {
                    okCall: function () {
                        $.post("/Permission/PermissionItem/Delete", { "Id": _selectedID_Permission_Item_Index }, dialogdel_Permission_Item_Index, "json");
                    }
                });
            } else {
                alertMsg.error("请先选择要删除的项！");
                return false;
            }
        });
        //GridGet_Permission_Item_Index();
    });

    function refreshTree(asyncUrl) {
        $("#getUrl").html("");
        $("#onAsyncSuccessNode").html("<br/>");
        $("#onAsyncErrorNode").html("<br/>");
        setting_Permission_Item_Index.asyncUrl = asyncUrl;
        if ((typeof asyncUrl) == "function") {
            $("#asyncUrlCode").html("setAsyncUrl");
        } else {
            $("#asyncUrlCode").html("\"" + asyncUrl + "\"");
        }
        zTree_Permission_Item_Index = $("#treeModule_Permission_Item_Index").zTree(setting_Permission_Item_Index, zNodes_Permission_Item_Index);
    }

    function dialogAdded_Permission_PermissionItem(json) {
        //提交回调
        //1 接收参数 2 判断成功与否 3 根据返回的数据在树上新增节点
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            $("#List_Permission_Item_Index").trigger("reloadGrid");
            $.pdialog.closeCurrent();
        }
    }

    //模块删除回调函数

    function dialogdel_Permission_Item_Index(json) {
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            //删除成功
            $("#List_Permission_Item_Index").trigger("reloadGrid");
            $("#add_Permission_Item_Index").attr("href", href__Permission_Item_Index + "/Create/{sid_user}");
            $("#edit_Permission_Item_Index").attr("href", href__Permission_Item_Index + "/Edit/{sid_user}");
            _selectedID_Permission_Item_Index = "";
        }
    }


    //*****以下是jqGrid

    function GridGet_Permission_Item_Index() {
        $("#List_Permission_Item_Index").jqGrid({
            url: "/Permission/PermissionItem/GetPermissionItemsByModuleId",
            datatype: "json",
            mtype: "post",
            colNames: ['ID', '名称', '编号', '有效', '备注'],
            colModel: [
                { label: 'ID', name: 'Id', index: 'Id', width: 5, align: "center", sortable: false, hidden: true },
                { label: '名称', name: 'FullName', index: 'FullName', width: 120, align: "center", sortable: false },
                { label: '编号', name: 'Code', index: 'Code', width: 100, align: "center", sortable: false },
                { label: '有效', name: 'Enabled', index: 'Enabled', width: 100, align: "center", formatter: "checkbox", sortable: false },
                { label: '备注', name: 'Description', index: 'Description', width: 150, align: "center", sortable: false }
            ],
            beforeRequest: function (d) {
                var selectedNode = zTree_Permission_Item_Index.getSelectedNode();
                if (selectedNode != null)
                    $(this).jqGrid('setGridParam', { postData: { "id": selectedNode.Id} });
            },
            loadError: function (xhr, status) {
                alertMsg.error(xhr.responseText);
            },
            loadComplete: function (xhr) {
                var ajaxbg = $("#background,#progressBar,#lui_List_Permission_Item_Index");
                ajaxbg.hide();
            },
            onSelectRow: function (rowid, status) {
                _selectedID_Permission_Item_Index = $("#List_Permission_Item_Index").getCell(rowid, "Id");
                var editUrl_Permission_Item_Index = href__Permission_Item_Index + "/Edit/" + _selectedID_Permission_Item_Index;
                $("#edit_Permission_Item_Index").attr("href", editUrl_Permission_Item_Index);
            },
            autowidth: true,
            shrinkToFit: true,
            multiselect: false,
            multiselectWidth: 50,
            sortable: false,
            viewrecords: true,
            sortorder: "desc",
            jsonReader: {
                repeatitems: false
            },
            height: contentHeight_Permission_Item_Index - 48
        }).navGrid('#pager_List_Permission_Item_Index', { edit: false, add: false, del: false, refresh: false, search: false });
    }
</script>

<div class="page">
    @*顶部按钮*@
    <div class="panelBar">
        <ul class="toolBar">
            @*<li><a class="add" id="add_Permission_Item_Index" href="/Permission/PermissionItem/Create/{sid_user}" rel="new"  target="dialog" mask="true"><span>添加</span></a></li>
			                <li><a class="edit" id="edit_Permission_Item_Index" href="/Permission/PermissionItem/Edit/{sid_user}" rel="new_edit"  target="dialog" mask="true"><span>修改</span></a></li>
                            <li><a class="move" id="move_Permission_Item_Index" href="/Permission/PermissionItem/SelectTree/{sid_user}" rel="new_move" title="请选择..." mask="true" width="280" height="350"  target="dialog"><span>移动</span></a></li>
			                <li><a class="delete" id="del_Permission_Item_Index" href="javascript:void(0);"><span>删除</span></a></li>*@
            <li>@Html.PermissionButton("Permission.PermissionItem.Create", "add_Permission_Item_Index", "add", "/Permission/PermissionItem/Create/{sid_user}", "new", "dialog", "添加", "true","400","320", "添加")</li>
            <li>@Html.PermissionButton("Permission.PermissionItem.Edit", "edit_Permission_Item_Index", "edit", "/Permission/PermissionItem/Edit/{sid_user}", "new_edit", "dialog", "编辑", "true", "400", "320", "编辑")</li>
            <li>@Html.PermissionButton("Permission.PermissionItem.Delete", "del_Permission_Item_Index", "delete", "javascript:void(0);", "", "", "", "", "删除")</li>
            <li class="line">line</li>
        </ul>
    </div>
    <div id="mainContent_Permission_Item_Index">
        <div id="Permission_Item_Index_LeftPane" class="leftPanel">
            @*菜单树*@
            <ul id="treeModule_Permission_Item_Index" class="ztree">
            </ul>
        </div>
        @*表单内容*@
        <div class="rightPanel">
            <table id="List_Permission_Item_Index">
            </table>
            <div id="pager_Permission_Item_Index">
            </div>
        </div>
    </div>
</div>
